package leetcode;

public class LeetCode12 {
    public String intToRoman(int num) {
        StringBuilder sb = new StringBuilder();
        int[] intDict = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
        String[] strDict = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
        int n = 0;
        for (int i = 0; i < intDict.length; i++) {
            n = num / intDict[i];
            num %= intDict[i];
            for (int j = 0; j < n; j++) {
                sb.append(strDict[i]);
            }
            if (num == 0)
                break;
        }
        return sb.toString();
    }
//------------------------------------------------------------------
}
